package com.nanhang.controller;


import com.nanhang.entity.SpecificationOption;
import com.nanhang.service.SpecificationOptionService;
import com.nanhang.service.SpecificationService;
import com.nanhang.util.PageResult;
import com.nanhang.util.R;
import com.nanhang.vo.SpecificationOptionVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/specificationOption")
public class SpecificationOptionController {

    @Autowired
    private SpecificationOptionService specificationOptionService;

    @GetMapping("/list")
    public List<SpecificationOption> list(){
        return specificationOptionService.findAll();
    }


    @GetMapping("/findByPage")
    public PageResult<SpecificationOption> findByPage(@RequestParam("page") Integer page, @RequestParam("pageSize") Integer pageSize){
        return specificationOptionService.findByPage(page,pageSize);
    }

    @PostMapping("/search")
    public PageResult<SpecificationOption> search(@RequestParam("page") Integer page,
                                      @RequestParam("pageSize") Integer pageSize,
                                      @RequestBody(required = false) SpecificationOptionVO specificationOptionvo){
        return specificationOptionService.search(page,pageSize,specificationOptionvo);
    }


    @PostMapping("/save")
    public R save(@RequestBody SpecificationOption specificationOption){
        return specificationOptionService.save(specificationOption) ? R.ok().message("添加成功！") : R.error().message("添加失败！");
    }
}
